package daoImpl;

import baseDao.BaseDao;
import dao.*;
import entity.Reply;

import java.sql.*;

/**
 * Created by miaoyu on 2017/7/12.
 */
public class ReplyDapImpl extends BaseDao implements dao.ReplyDao {
    /**
     * 加入一个评论
     * @param reply reply对象
     * @return 改变行数
     */
    public int addReply(Reply reply) {
        Object obj1[] = {reply.getUserID(),reply.getTime(),reply.getContent()};
        int row1 = executeUpdate("INSERT INTO floor(userID,time,content) values(?,?,?)",obj1);
        Object obj2[] = {getReplyID(reply.getUserID(),reply.getTime()),reply.getReplyID()};
        int row2 = executeUpdate("INSERT INTO reply values(?,?)",obj2);
        return row1+row2;
    }

    /**
     * 获得reply的floorID
     * @param userID 用户ID
     *         time 发布时间
     * @return
     */
    public int getReplyID(int userID,String time){
        return new FloorDaoImpl().getFloorID(userID,time);
    }
}
